/**
 * 
 */
package com.orange.controller.expert;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.orange.controller.BaseController;
import com.orange.dbhelp.page.Page;
import com.orange.handler.AuthExpertService;
import com.orange.handler.AuthExportGroupMapService;
import com.orange.handler.AuthExportGroupService;
import com.orange.handler.AuthItemService;
import com.orange.handler.AuthSchoolService;
import com.orange.handler.expert.AuthExpertItemMapService;
import com.orange.handler.expert.AuthExpertSchoolMapService;
import com.orange.modules.bean.SchoolItemBean;
import com.orange.modules.bean.SessionUser;
import com.orange.modules.entity.AuthItem;
import com.orange.modules.entity.expert.AuthExpert;
import com.orange.modules.entity.expert.AuthExpertItemData;
import com.orange.modules.entity.expert.AuthExpertItemMap;
import com.orange.modules.entity.expert.AuthExpertSchoolMap;
import com.orange.modules.entity.expert.AuthExportGroupMap;
import com.orange.modules.entity.expert.AuthGroup;
import com.orange.modules.entity.school.AuthSchool;
import com.orange.modules.entity.school.AuthSchoolGroupMap;
import com.orange.util.DocumentHandler;
import com.orange.util.ReturnCode;

/**
 * @author gaogs
 *
 * 2016-12-12
 */
@Controller
@RequestMapping("/MaterialExpert")
public class AuthMaterialExpertController extends BaseController {
	
	private static final Logger logger = Logger.getLogger(AuthMaterialExpertController.class);
	
	@Autowired
	private AuthExportGroupService authExportGroupService;
	
	@Autowired
	private AuthExportGroupMapService authExportGroupMapService;
	
	@Autowired
	private AuthSchoolService authSchoolService;
	
	@Autowired
	private AuthExpertService authExpertService;
	
	@Autowired
	private AuthExpertSchoolMapService authExpertSchoolMapService;
	
	@Autowired
	private AuthExpertItemMapService authExpertItemMapService;
	
	@Autowired
	private AuthItemService authItemService;
	
	
	
	/**
	 * 创建材料评审专家组
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/saveAuthExpertGroup_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertGroup_material(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try {
			if(StringUtils.isBlank(map.get("name"))){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"参数存在空值");
			}
			
			AuthGroup a=new AuthGroup();
			a.setName(map.get("name"));
			a.setState("0");
			a.setType("0");
			String nowTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
			a.setCreateTime(nowTime);
			a.setUpdateTime(nowTime);
			authExportGroupService.saveAuthExportGroupInfo(a);
			return toResponse(null,ReturnCode.SUCCESS,"创建专家组成功");
		} catch (Exception e) {
			logger.info("创建专家组失败",e);
			return toResponse(null,ReturnCode.FAIL,"创建专家组失败");
		}
	}
	
	
	/**
	 * 删除材料评审专家组
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/deleteAuthExpertGroup_material", produces = MediaType.APPLICATION_JSON_VALUE
			+ ";charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> deleteAuthExpertGroup_material(HttpServletRequest request, @RequestParam String pid)
			throws SQLException {
		try {
			if (StringUtils.isBlank(pid)) {
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL,"删除Id不能为空");
			}
			AuthGroup ag = authExportGroupService.queryAuthExportGroupInfo(pid);
			if(null==ag){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST,"该材料评审专家组信息不存在");
			}
			
			//根据专家组id查询所有绑定的专家
			List<AuthExportGroupMap> ls=authExportGroupMapService.queryAuthExportGroupMapByGroupId(pid);
			List<AuthExpert> list=new ArrayList<AuthExpert>();
			if(ls.size()>0){
				for(AuthExportGroupMap a:ls){
					AuthExpert ae=authExpertService.queryAuthExpertInfoById(a.getExportId());
					if(null==ae){
						return toResponse(null, ReturnCode.USERINFO_NOT_EXIST, "专家信息不存在");
					}
					ae.setStatuss("0");//绑定的专家解绑
					list.add(ae);
				}
			}
			authExpertService.saveAuthExpertInfos(list);
			authExportGroupService.deleteAuhExportGroupInfo(ag.getPid());//删除组

			return toResponse(null, ReturnCode.SUCCESS, "删除现场考察专家组成功");
		} catch (Exception e) {
			logger.info("删除现场考察专家组失败",e);
			return toResponse(null, ReturnCode.FAIL, "删除现场考察专家组失败");
		}
	}

	/**
	 * 修改材料评审专家组信息
	 */
	@RequestMapping(value = "/updateAuthExpertGroup_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> updateAuthExpertGroup_material(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try{
			String pid = map.get("pid");
			String name = map.get("name");
			if(StringUtils.isBlank(name)||StringUtils.isBlank(pid)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"参数存在空值");
			}
			AuthGroup ag = authExportGroupService.queryAuthExportGroupInfo(pid);
			if(ag == null){
				return toResponse(null,ReturnCode.FAIL,"该材料评审专家组不存在");
			}
			ag.setName(name);
			String nowTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
			ag.setUpdateTime(nowTime);
			authExportGroupService.saveAuthExportGroupInfo(ag);
			return toResponse(ag,ReturnCode.SUCCESS,"修改材料评审专家组信息成功");
		}catch(Exception e){
			logger.info("修改材料评审专家组信息失败",e);
			return toResponse(null,ReturnCode.FAIL,"修改材料评审专家组信息失败");
		}
	}
	
	/**
	 * 分页查询材料评审专家组
	 * 
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryAuthGroupPage_material", produces = MediaType.APPLICATION_JSON_VALUE
			+ ";charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthGroupPage_material(HttpServletRequest request, @RequestBody Map<String, String> map)throws SQLException {
		
		try {
			String pageNumber = map.get("pageNumber");
			String pageSize = map.get("pageSize");
			if (StringUtils.isBlank(pageNumber))
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "数量不能为空!");
			if (StringUtils.isBlank(pageSize))
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "页数不能为空!");
			
			Page<AuthGroup> page = authExportGroupService.queryAuthGroupPage_material(map);
			return toResponse(page, ReturnCode.SUCCESS, "分页查询材料评审专家组成功");
		} catch (Exception e) {
			logger.info("分页查询材料评审专家组失败", e);
			return toResponse(null, ReturnCode.FAIL, "分页查询材料评审专家组失败");
		}
	}
	
	
	/**
	 * 查询未绑定材料评审专家组的所有组员
	 * 
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryUnAuthExpertList_material", produces = MediaType.APPLICATION_JSON_VALUE
			+ ";charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryUnAuthExpertList_material(HttpServletRequest request, @RequestBody Map<String, String> map)throws SQLException {
		
		try {
			List<AuthExpert> list=authExpertService.queryUnAuthExpertList_material();
			return toResponse(list, ReturnCode.SUCCESS, "查询未绑定材料评审专家组的所有组员成功");
		} catch (Exception e) {
			logger.info("查询未绑定材料评审专家组的所有组员失败", e);
			return toResponse(null, ReturnCode.FAIL, "查询未绑定材料评审专家组的所有组员失败");
		}
	}
	
	/**
	 * 材料评审专家组-添加组员
	 */
	@RequestMapping(value = "/addAuthExportGroupMap_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> addAuthExportGroupMap_material(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try{
			String exportIds = map.get("exportIds");
			String groupId = map.get("groupId");
			
			if(StringUtils.isBlank(exportIds)|| StringUtils.isBlank(groupId))
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "专家组id或者专家为空");
			
			List<AuthExportGroupMap> list=new ArrayList<AuthExportGroupMap>();
			List<AuthExpert> as=new ArrayList<AuthExpert>();
			String [] strs=exportIds.split(",");
			if(strs.length>0){
				String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
				for(int i=0 ;i<strs.length ;i++){
					// 设置专家状态为绑定状态
					AuthExpert ae=authExpertService.queryAuthExpertInfoById(strs[i]);
					if(null==ae){
						return toResponse(null, ReturnCode.USERINFO_NOT_EXIST, "专家信息不存在");
					}
//					if("1".equals(ae.getStatus())){
//						return toResponse(null, ReturnCode.SCHOOL_HAVE_GROUP, "专家已绑定现场考察专家组");
//					}
					ae.setStatuss("1");
					as.add(ae);
					
					AuthExportGroupMap a=new AuthExportGroupMap();
					a.setCreateTime(nowTime);
					a.setExportId(strs[i]);
					a.setGroupId(groupId);
					a.setIdentitys("0");
					a.setType("0");
					list.add(a);
				}
			}
			authExportGroupMapService.addAuthExportGroupMapList(list);
			authExpertService.saveAuthExpertInfos(as);
			return toResponse(null, ReturnCode.SUCCESS, "材料评审专家组-添加组员成功");
		}catch(Exception e){
			logger.info("材料评审专家组-添加组员失败", e);
			return toResponse(null,ReturnCode.FAIL,"材料评审专家组-添加组员失败");
		}
	}
	
	
	/**
	 * 删除材料评审专家组组员
	 * 
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/deleteAuthExpertGroupMap_material", produces = MediaType.APPLICATION_JSON_VALUE
			+ ";charset=UTF-8", method = RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> deleteAuthExpertGroupMap_material(HttpServletRequest request, @RequestParam String pid)
			throws SQLException {
		try {
			if (StringUtils.isBlank(pid)) {
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL,"删除Id不能为空");
			}
			AuthExportGroupMap aa=authExportGroupMapService.queryAuthExportGroupMapById(pid);
			if(null==aa){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST,"该组员记录不存在");
			}
			AuthGroup ag = authExportGroupService.queryAuthExportGroupInfo(aa.getGroupId());
			if(null==ag){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST,"该材料评审专家组信息不存在");
			}
			AuthExpert ae=authExpertService.queryAuthExpertInfoById(aa.getExportId());
			if(null==ae){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST,"该专家记录不存在");
			}
			ae.setStatuss("0");
			authExpertService.updateAuthExpert(ae);
			authExportGroupMapService.deleteAuthExportGroupMapById(pid);
			return toResponse(null, ReturnCode.SUCCESS, "删除材料评审专家组成功");
		} catch (Exception e) {
			logger.info("删除材料评审专家组失败",e);
			return toResponse(null, ReturnCode.FAIL, "删除材料评审专家组失败");
		}
	}
	
	/**
	 *   分页查看材料评审专家组内 所有专家
	 */
	@RequestMapping(value = "/queryAuthExportGroupMapPage" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthExportGroupMapPage(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try{
			String pageSize = map.get("pageSize");
			String pageNumber = map.get("pageNumber");
			String groupId = map.get("groupId");
			
			if(StringUtils.isBlank(pageSize)||StringUtils.isBlank(pageNumber)||StringUtils.isBlank(groupId)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数存在空值");
			}
			Page<AuthExportGroupMap> ls=authExportGroupMapService.queryAuthExportGroupMapPage(map);
			return toResponse(ls, ReturnCode.SUCCESS, "分页查看材料评审专家组内 所有专家成功");
		}catch(Exception e){
			logger.info("分页查看材料评审专家组内 所有专家失败", e);
			return toResponse(null,ReturnCode.FAIL,"分页查看材料评审专家组内 所有专家失败");
		}
	}
	
	/**
	 *   设置材料评审专家组 组员身份
	 */
	@RequestMapping(value = "/setAuthExportIdentity_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> setAuthExportIdentity_material(HttpServletRequest request,@RequestParam String pid,@RequestParam String identity) throws SQLException{
		
		try{
			if(StringUtils.isBlank(pid)||StringUtils.isBlank(identity)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数存在空值");
			}
			AuthExportGroupMap aa=authExportGroupMapService.queryAuthExportGroupMapById(pid);
			if(null==aa){
				return toResponse(null,ReturnCode.USERINFO_NOT_EXIST,"该组员关系不存在");
			}
			
			if(!"0".equals(identity)&&!"1".equals(identity)&&!"2".equals(identity)&&!"3".equals(identity)){
				return toResponse(null,ReturnCode.FAIL,"身份别瞎填！");
			}
			AuthGroup ag = authExportGroupService.queryAuthExportGroupInfo(aa.getGroupId());
			if(null==ag){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST,"该材料评审专家组信息不存在");
			}
			aa.setIdentitys(identity);
			if(!"0".equals(identity)){
				AuthExportGroupMap a1=authExportGroupMapService.queryAuthExportGroupMapByIdentity(aa.getGroupId(), identity);
				if(null!=a1){
					a1.setIdentitys("0");
					authExportGroupMapService.saveAuthExportGroupMap(a1);
				}
			}
			authExportGroupMapService.saveAuthExportGroupMap(aa);
			
			return toResponse(null, ReturnCode.SUCCESS, "设置材料评审专家组 组员身份成功");
		}catch(Exception e){
			logger.info("设置材料评审专家组 组员身份失败", e);
			return toResponse(null,ReturnCode.FAIL,"设置材料评审专家组 组员身份失败");
		}
	}
	
	
	/**
	 * 查询需要绑定材料评审的所有机构
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryAuthSchoolList_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthSchoolList_material(HttpServletRequest request,@RequestParam String expertId) throws SQLException{
		
		try {
			List<AuthSchool>ls=authSchoolService.queryAuthSchoolListHaveSubmit();
			List<AuthExpertSchoolMap> list=authExpertSchoolMapService.queryAuthExpertSchoolMapInfoByExpert(expertId);
			if(ls.size()>0){
				Map<String ,String>map=new HashMap<String, String>();
				if(list.size()>0){
					for(AuthExpertSchoolMap ae:list){
						map.put(ae.getSchoolId(), ae.getPid());
					}
				}
				for(AuthSchool a:ls){
					if(StringUtils.isNotBlank(map.get(a.getPid()))){
						a.setFlag("1");
					}else{
						a.setFlag("0");
					}
				}
			}
			return toResponse(ls,ReturnCode.SUCCESS,"查询需要绑定材料评审的所有机构成功");
		} catch (Exception e) {
			logger.info("查询需要绑定材料评审的所有机构失败",e);
			return toResponse(null,ReturnCode.FAIL,"查询需要绑定材料评审的所有机构失败");
		}
		
	}
	
	/**
	 * 为专家绑定机构
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/saveAuthExpertSchoolMap_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertSchoolMap_material(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try {
			String schoolIds=map.get("schoolIds");//需要绑定的机构id 以,拼接
			String expertId=map.get("expertId");//专家id
			if(StringUtils.isBlank(schoolIds)||StringUtils.isBlank(expertId)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数存在空值");
			}
			AuthExportGroupMap aeg=authExportGroupMapService.queryAuthExportGroupMapByExpertId_material(expertId);
			if(null==aeg){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST, "该专家非材料评审专家组成员");
			}
			
			
			
			
			authExpertSchoolMapService.deleteAuthExpertSchoolMapInfo(expertId);//删除专家与机构的绑定关系
			authExpertItemMapService.deleteAuthExpertItemMapByExpertId(expertId,null);//删除专家与一级指标的绑定关系
			
			List<AuthExpertSchoolMap>l=new ArrayList<AuthExpertSchoolMap>();
			String []strs=schoolIds.split(",");
			if(strs.length>0){
				String nowTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
				for(int i=0;i<strs.length;i++){
					AuthExpertSchoolMap ae=new AuthExpertSchoolMap();
					ae.setExpertId(expertId);
					ae.setGroupId(aeg.getGroupId());
					ae.setSchoolId(strs[i]);
					ae.setCreateTime(nowTime);
					l.add(ae);
				}
				authExpertSchoolMapService.saveAuthExpertSchoolMapList(l);
			}
			return toResponse(null,ReturnCode.SUCCESS,"专家绑定机构成功");
		} catch (Exception e) {
			logger.info("专家绑定机构失败",e);
			return toResponse(null,ReturnCode.FAIL,"专家绑定机构失败");
		}
		
	}
	
	
	/**
	 * 查询专家已绑定的机构
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryHaveAuthSchoolList_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryHaveAuthSchoolList_material(HttpServletRequest request,@RequestParam String expertId) throws SQLException{
		
		try {
			if(StringUtils.isBlank(expertId)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"专家id不可为空");
			}
			List<AuthExpertSchoolMap> list=authExpertSchoolMapService.queryAuthExpertSchoolMapInfoByExpert(expertId);
			return toResponse(list,ReturnCode.SUCCESS,"查询需要绑定材料评审的所有机构成功");
		} catch (Exception e) {
			logger.info("查询需要绑定材料评审的所有机构失败",e);
			return toResponse(null,ReturnCode.FAIL,"查询需要绑定材料评审的所有机构失败");
		}
		
	}
	
	/**
	 * 查询专家需要绑定的一级指标
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryAuthitemList_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthitemList_material(HttpServletRequest request,@RequestParam String expertId,@RequestParam  String schoolId) throws SQLException{
		
		try {
			if(StringUtils.isBlank(expertId)||StringUtils.isBlank(schoolId)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"参数存在空值");
			}
			List<AuthItem> list=authItemService.queryAuthItemByFid("0", "0");
			List<AuthExpertItemMap> l=authExpertItemMapService.queryAuthExpertItemMapListByExpertId(expertId, schoolId);
			if(list.size()>0){
				Map<String ,String>map=new HashMap<String, String>();
				if(l.size()>0){
					for(AuthExpertItemMap ae:l){
						map.put(ae.getItemId(), ae.getPid());
					}
				}
				for(AuthItem a:list){
					if(StringUtils.isNotBlank(map.get(a.getPid()))){
						a.setFlag("1");
					}else{
						a.setFlag("0");
					}
				}
			}
			return toResponse(list,ReturnCode.SUCCESS,"查询专家需要绑定的一级指标成功");
		} catch (Exception e) {
			logger.info("查询专家需要绑定的一级指标失败",e);
			return toResponse(null,ReturnCode.FAIL,"查询专家需要绑定的一级指标失败");
		}
		
	}
	
	/**
	 * 为专家绑定一级指标
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/saveAuthExpertItemMap_material" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertItemMap_material(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		
		try {
			String itemIds=map.get("itemIds");//需要一级指标的id 以,拼接
			String expertId=map.get("expertId");//专家id
			String schoolId=map.get("schoolId");//学校id
			if(StringUtils.isBlank(itemIds)||StringUtils.isBlank(expertId)||StringUtils.isBlank(schoolId)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数存在空值");
			}
			AuthExportGroupMap aeg=authExportGroupMapService.queryAuthExportGroupMapByExpertId_material(expertId);
			if(null==aeg){
				return toResponse(null, ReturnCode.USERINFO_NOT_EXIST, "该专家非材料评审专家组成员");
			}
			
			authExpertItemMapService.deleteAuthExpertItemMapByExpertId(expertId,schoolId);//删除专家与一级指标的绑定关系
			
			List<AuthExpertItemMap>l=new ArrayList<AuthExpertItemMap>();
			String []strs=itemIds.split(",");
			if(strs.length>0){
				String nowTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
				for(int i=0;i<strs.length;i++){
					AuthExpertItemMap ae=new AuthExpertItemMap();
					ae.setExpertId(expertId);
					ae.setGroupId(aeg.getGroupId());
					ae.setSchoolId(schoolId);
					ae.setItemId(strs[i]);
					ae.setCreateTime(nowTime);
					ae.setState("0");
					l.add(ae);
				}
				authExpertItemMapService.saveAuthExpertItemMapList(l);
			}
			return toResponse(null,ReturnCode.SUCCESS,"专家绑定一级指标成功");
		} catch (Exception e) {
			logger.info("专家绑定一级指标失败",e);
			return toResponse(null,ReturnCode.FAIL,"专家绑定一级指标失败");
		}
		
	}
	
	
	/****************************************材料评审专家页面接口*******************************************/
	
	/**
	 * 专家信息登记
	 */
	@RequestMapping(value="/saveAuthExpertInfoById" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertInfoById(HttpServletRequest request,HttpServletResponse response ,@RequestBody Map<String, String> map){
		
		try {
			String pid = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
			if(StringUtils.isBlank(pid)){
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"未登录");
			}
			AuthExpert ae = authExpertService.queryAuthExpertInfoById(pid);
			String expertcode = map.get(ae.getExpertcode());
			String expertname = map.get(ae.getExpertname());
			String title = map.get("title");
			String post = map.get("post");
			String field = map.get("field");
			String officephone = map.get("officephone");
			String phone = map.get("phone");
			String email = map.get("email");
			String workunit = map.get("workunit");
			if(expertcode!=null && StringUtils.isNotBlank(expertcode))
				ae.setExpertcode(expertcode);
			if(expertname!=null && StringUtils.isNotBlank(expertname))
				ae.setExpertname(expertname);
			if(title!=null && StringUtils.isNotBlank(title))
				ae.setTitle(title);
			if(post!=null && StringUtils.isNotBlank(post))
				ae.setPost(post);
			if(field!=null && StringUtils.isNotBlank(field))
				ae.setField(field);
			if(officephone!=null && StringUtils.isNotBlank(officephone))
				ae.setOfficephone(officephone);
			if(phone!=null && StringUtils.isNotBlank(phone))
				ae.setPhone(phone);
			if(email!=null && StringUtils.isNotBlank(email))
				ae.setEmail(email);
			if(workunit!=null && StringUtils.isNotBlank(workunit))
				ae.setWorkunit(workunit);
			authExpertService.insertAuthExpert(ae);
			return toResponse(ae, ReturnCode.SUCCESS, "信息登记成功");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(e, ReturnCode.FAIL, "信息登记失败");
		}
		
	}

	/**
	 * 材料评审-- 查看一级指标材料评审分项意见记录表中的学校
	 */
	@RequestMapping(value = "/queryAuthSchoolInfo" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthSchoolInfo(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		String pageSize = map.get("pageSize");
		String pageNumber = map.get("pageNumber");
		if(StringUtils.isBlank(pageNumber) || StringUtils.isBlank(pageSize)){
			return toResponse(null, ReturnCode.FAIL, "参数存在空值!");
		}
		try {
			Page<SchoolItemBean> page = authExpertSchoolMapService.queryAuthSchoolPageByExportId(expertId, map);
			return toResponse(page, ReturnCode.SUCCESS, "查询成功!!!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.FAIL, "查询失败");
		}
		
	}
	
	/**
	 * 材料评审-- 查看一级指标材料评审分项意见记录表中的学校对应的指标
	 */
	@RequestMapping(value = "/queryAuthItemInfo" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthItemInfo(HttpServletRequest request,@RequestParam String schoolId){
		String expertId =(String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		try {
			List<AuthItem> list = authExpertSchoolMapService.queryAuthItemBySchoolIdAndExpertId(schoolId, expertId);
			return toResponse(list, ReturnCode.SUCCESS, "一级指标查询成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.FAIL, "一级指标查询失败!");
		}
		
	}
	
	/**
	 * 材料评审--修改查询材料评审分项意见记录表
	 */
	@RequestMapping(value = "/queryAuthItem" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthItem(HttpServletRequest request,@RequestParam String schoolId, @RequestParam String itemId, @RequestParam String state){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		try {
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(schoolId);
			List<AuthItem> list = new ArrayList<AuthItem>();
			List<AuthItem> list2 = new ArrayList<AuthItem>();
			if(state.equals("1") || state.equals("2")){
				list = authItemService.queryAuthItemByFidAndTypeAndMajor(itemId, "1", as.getMajor(),schoolId);//查询对应的二级指标
				for (AuthItem authItem : list) {
					authItem.setList(authItemService.queryAuthItemByFidAndTypeAndMajor(authItem.getPid(), "2", as.getMajor(),schoolId));
					list2.add(authItem);
				}
			}else{
				list = authItemService.queryAuthItemByFidAndTypeAndMajor2(itemId, "1", as.getMajor());
				for (AuthItem authItem : list) {
					authItem.setList(authItemService.queryAuthItemByFidAndTypeAndMajor2(authItem.getPid(), "2", as.getMajor()));
					list2.add(authItem);
				}
			}
			return toResponse(list2, ReturnCode.SUCCESS, "查询成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "查询失败!");
		}
	}
	
	/**
	 *  材料评审--保存查询材料评审分项意见记录表
	 */
	@RequestMapping(value = "/saveAuthExpertItemData" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertItemData(HttpServletRequest request,/*@RequestParam String schoolId, @RequestParam String itemId,*/ @RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String schoolId = map.get("schoolId");
		String itemId = map.get("itemId");
		try {
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(schoolId);
			if(null==as){
				return toResponse(null, ReturnCode.FAIL, "学校不存在!");
			}
			AuthExportGroupMap aeg = authExportGroupMapService.queryGroupId(expertId);
			if(null==aeg){
				return toResponse(null, ReturnCode.FAIL, "未绑定专家组!");
			}
			String groupId = aeg.getGroupId();
			
			String valueTiwce = map.get("twoLevel");
			String mainProblem = map.get("mainProblem");
			String valueInfo = map.get("detailLevel");
			if(valueTiwce==null || StringUtils.isBlank(valueTiwce))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"二级指标等级不能为空");
			if(valueInfo==null || StringUtils.isBlank(valueInfo))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"细则等级不能为空");
			if(mainProblem==null || StringUtils.isBlank(mainProblem))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"反馈问题不能为空");
			String[] valueTiwceList = valueTiwce.split("#");
			String[] mainProblemList =  mainProblem.split("#");
			String[] valueInfoList = valueInfo.split("#");
			
			
			List<AuthItem> list = new ArrayList<AuthItem>();
			list = authItemService.queryAuthItemByFidAndTypeAndMajor2(itemId, "1", as.getMajor());//查询对应的二级指标
			if(null!=list){
				for (int i = 0; i < list.size(); i++) {	
					String indexId = list.get(i).getPid();
					String nowTime = sdf.format(new Date());
					AuthExpertItemData ad = new AuthExpertItemData();
					ad.setExpertId(expertId);
					ad.setGroupId(groupId);
					ad.setItemId(itemId);
					ad.setSchoolId(schoolId);
					ad.setCreateTime(nowTime);
					ad.setIndexId(indexId);
					if(mainProblemList[i].equals(" ")){
						ad.setMainProblem(null);
					}else{
						ad.setMainProblem(mainProblemList[i]);
					}
					ad.setValue(valueTiwceList[i]);
					ad.setType("1");
					authExpertItemMapService.deleteAuthExpertItemData(expertId, "1", indexId,schoolId);
					authExpertItemMapService.saveAuthItemExpertData(ad);
					
					String[] valueInfoList1 = valueInfoList[i].split(",");
					List<AuthItem> list1 = new ArrayList<AuthItem>();
					list1 = authItemService.queryAuthItemByFidAndTypeAndMajor2(list.get(i).getPid(), "2", as.getMajor());
					if(null!=list1){
						for (int j = 0; j < list1.size(); j++) {
							AuthExpertItemData ad1 = new AuthExpertItemData();
							ad1.setExpertId(expertId);
							ad1.setGroupId(groupId);
							ad1.setItemId(itemId);
							ad1.setSchoolId(schoolId);
							ad1.setCreateTime(nowTime);
							ad1.setIndexId(list1.get(j).getPid());
							ad1.setValue(valueInfoList1[j]);
							ad1.setType("2");
							authExpertItemMapService.deleteAuthExpertItemData(expertId, "2", list1.get(j).getPid(),schoolId);
							authExpertItemMapService.saveAuthItemExpertData(ad1);
						}
					}
				}
			}
			AuthExpertItemMap am = new AuthExpertItemMap();
			am = authExpertItemMapService.queryState(schoolId, itemId, expertId);
			am.setState("1");
			authExpertItemMapService.saveAuthState(am);
			return toResponse(null, ReturnCode.SUCCESS, "保存成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.FAIL, "保存失败!");
		}
	}
	
	/**
	 * 提交材料评审分项意见记录表
	 */
	@RequestMapping(value = "/saveAuthExpertItemDataTable" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthExpertItemDataTable(HttpServletRequest request, @RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		String schoolId = map.get("schoolId");
		String itemId = map.get("itemId");
		AuthExpertItemMap am = new AuthExpertItemMap();
		try {
			am = authExpertItemMapService.queryState(schoolId, itemId, expertId);
			am.setState("2");
			authExpertItemMapService.saveAuthState(am);
			return toResponse(null, ReturnCode.SUCCESS, "提交成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.FAIL, "提交失败!");
		}
		
	}
	
	/**
	 * 材料汇总表--显示绑定学校的分项意见记录表列表中的学校
	 */
	@RequestMapping(value = "/queryAuthSchoolList" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthSchoolList(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		String pageSize = map.get("pageSize");
		String pageNumber = map.get("pageNumber");
		String groupId = map.get("pid");
		if(StringUtils.isBlank(pageNumber) || StringUtils.isBlank(pageSize)){
			return toResponse(null, ReturnCode.FAIL, "参数存在空值!");
		}
		try {
			if(groupId.equals("")){
				Page<SchoolItemBean> page = authExpertSchoolMapService.queryAuthSchoolPageByGroupId(expertId, map);
				return toResponse(page, ReturnCode.SUCCESS, "学校列表查询成功!");
			}else{
				Page<SchoolItemBean> page = authExpertSchoolMapService.queryAuthSchoolPageByGroupId1(groupId, map);
				return toResponse(page, ReturnCode.SUCCESS, "学校列表查询成功!");
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "学校列表查询失败!");
		}
		
	}
	
	/**
	 * 材料汇总表--显示绑定学校的分项意见记录表列表中的指标
	 */
	@RequestMapping(value = "/queryAuthAllItem" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthAllItem(HttpServletRequest request,@RequestParam String schoolId){
		/*String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}*/
		try {
			List<AuthItem> list = authItemService.queryAuthItemAndExpert(schoolId);
			return toResponse(list, ReturnCode.SUCCESS, "查询成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "查询失败!");
		}
		
	}
	
	/**
	 * 材料汇总表--汇总
	 */
	@RequestMapping(value = "/queryAuthCollect" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryAuthCollect(HttpServletRequest request,@RequestParam String schoolId){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		try {
			List<AuthItem> list = new ArrayList<AuthItem>();
			list = authItemService.queryAuthItemTwice("0");
			List<AuthItem> list1 = new ArrayList<AuthItem>();
			for (AuthItem authItem : list) {
				authItem.setList(authItemService.queryAuthCollect(schoolId, authItem.getPid()));
				list1.add(authItem);
			}
			/*AuthExportGroupMap aeg = authExportGroupMapService.queryGroupId(expertId);
			if(null==aeg){
				return toResponse(null, ReturnCode.FAIL, "未绑定专家组!");
			}
			String groupId = aeg.getGroupId();
			AuthItem ai = new AuthItem();
			ai = authItemService.queryIsfollow(schoolId, groupId);
			list1.add(ai);*/
			return toResponse(list1, ReturnCode.SUCCESS, "查询成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "查询失败!");
		}
	}
	
	/**
	 * 材料汇总表--保存专家组评议和建议结果
	 */
	@RequestMapping(value = "/saveAuthItemReview" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> saveAuthItemReview(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTime = sdf.format(new Date());
		String schoolId = map.get("schoolId");
		String isfollow = map.get("isfollow");
		try {
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(schoolId);
			if(null==as){
				return toResponse(null, ReturnCode.FAIL, "学校不存在!");
			}
			AuthExportGroupMap aeg = authExportGroupMapService.queryGroupId(expertId);
			if(null==aeg){
				return toResponse(null, ReturnCode.FAIL, "未绑定专家组!");
			}
			String groupId = aeg.getGroupId();
			
			String valueTiwce = map.get("expertResults");
			String mainProblem = map.get("mainProblems");
			String valueInfo = map.get("expertGroupResults");
			if(valueTiwce==null || StringUtils.isBlank(valueTiwce))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"二级指标等级不能为空");
			if(valueInfo==null || StringUtils.isBlank(valueInfo))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"评议等级不能为空");
			if(mainProblem==null || StringUtils.isBlank(mainProblem))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"反馈问题不能为空");
			String[] valueTiwceList = valueTiwce.split("#");
			String[] mainProblemList =  mainProblem.split("#");
			String[] valueInfoList = valueInfo.split("#");
			
			List<AuthItem> list = new ArrayList<AuthItem>();
			list = authItemService.queryAuthItemTwice("0");//查询六个一级指标
			List<AuthItem> list1 = new ArrayList<AuthItem>();
			List<AuthItem> list2 = new ArrayList<AuthItem>();
			if(null!=list){
				for (int i = 0; i < list.size(); i++) {
					list1 = authItemService.queryAuthItemByFidAndTypeAndMajor2(list.get(i).getPid(), "1", as.getMajor());//查询对应的二级指标
					for (int j = 0; j < list1.size(); j++) {
						AuthItem ai = authItemService.queryAuthItemByFidAndTypeAndMajor1(list1.get(j).getPid(), "1", as.getMajor(),schoolId);
						list2.add(ai);
					}
				}
			}
			if(null!=list1){
				for (int j = 0; j < list2.size(); j++) {
					String indexId = list2.get(j).getPid();
					
					AuthExpertItemData ad = new AuthExpertItemData();
					ad.setExpertId(list2.get(j).getExpertId());
					ad.setGroupId(groupId);
					ad.setItemId(list2.get(j).getFid());
					ad.setSchoolId(schoolId);
					ad.setCreateTime(nowTime);
					ad.setIndexId(indexId);
					if(mainProblemList[j].equals(" ")){
						ad.setMainProblem(null);
					}else{
						ad.setMainProblem(mainProblemList[j]);
					}
					ad.setValue(valueTiwceList[j]);
					ad.setReview(valueInfoList[j]);
					ad.setType("1");
					authExpertItemMapService.deleteAuthExpertItemData(list2.get(j).getExpertId(), "1", indexId,schoolId);
					authExpertItemMapService.saveAuthItemExpertData(ad);
				}
				
			}
				
			
			AuthSchoolGroupMap asg = new AuthSchoolGroupMap();
			asg.setSchoolId(schoolId);
			asg.setGroupId(groupId);
			asg.setCreateTime(nowTime);
			asg.setIsfollow(isfollow);
			asg.setCollect("2");
			authExportGroupMapService.deleteAuthSchoolGroupMap(schoolId, groupId);
			authExportGroupMapService.saveAuthSchoolGroupMap(asg);
			return toResponse(asg, ReturnCode.SUCCESS, "保存成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "保存失败!");
		}
		
		
	}
	
	/**
	 * 下载材料评审分项意见表格
	 */
	@RequestMapping(value="/writeWordFile" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public void writeWordFile(HttpServletRequest request,HttpServletResponse response, String schoolId,String itemId,String number) {    
		Map<String, Object> dataMap = new HashMap<String, Object>();
		try {
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(schoolId);
			String major = as.getMajor();
			dataMap.put("school", as.getSchoolName());
			if("0".equals(major)){
				dataMap.put("major", "学前教育");
			}else if("1".equals(major)){
				dataMap.put("major", "小学教育");
			}else{
				dataMap.put("major", "中学教育");
			}
			
			int x = 0;
			List<AuthItem> list = new ArrayList<AuthItem>();
			List<AuthItem> list1 = new ArrayList<AuthItem>();
			list = authItemService.queryAuthItemByFidAndTypeAndMajor(itemId, "1", as.getMajor(),schoolId);
			for (int i = 0; i < list.size(); i++) {
				dataMap.put("value"+i, list.get(i).getLevel());
				if("".equals(list.get(i).getMainProblem()) || StringUtils.isBlank(list.get(i).getMainProblem())){
					dataMap.put("problem"+i, "二级指标达标,无需填写");
				}else{
					dataMap.put("problem"+i, list.get(i).getMainProblem());
				}
				list1 = authItemService.queryAuthItemByFidAndTypeAndMajor(list.get(i).getPid(), "2", as.getMajor(),schoolId);
				for (int j = 0; j < list1.size(); j++) {
					dataMap.put("level"+x, list1.get(j).getLevel());
					x++;
				}
			}
				
			AuthItem ai = authItemService.queryAuthItemById(itemId);
			DocumentHandler mdoc = new DocumentHandler();
			if("1".equals(number)){
				mdoc.createDoc1(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}else if("2".equals(number)){
				mdoc.createDoc2(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}else if("3".equals(number)){
				mdoc.createDoc3(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}else if("4".equals(number)){
				mdoc.createDoc4(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}else if("5".equals(number)){
				mdoc.createDoc5(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}else if("6".equals(number)){
				mdoc.createDoc6(request,response,dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			}
	        
			//mdoc.createDoc3(dataMap, "D:/"+as.getSchoolName()+ai.getContent()+".doc");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
	}
	

	/**
	 * 下载材料评审汇总表格
	 */
	@RequestMapping(value="/downloadCollect" ,produces = MediaType.TEXT_HTML_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public void downloadCollect(HttpServletRequest request,HttpServletResponse response, String schoolId,String groupId) {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		try {
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(schoolId);
			String major = as.getMajor();
			if("0".equals(major)){
				dataMap.put("major", "学前教育");
			}else if("1".equals(major)){
				dataMap.put("major", "小学教育");
			}else{
				dataMap.put("major", "中学教育");
			}
			dataMap.put("school", as.getSchoolName());
			List<AuthItem> list1 = new ArrayList<AuthItem>();
			List<AuthItem> list = new ArrayList<AuthItem>();
			list = authItemService.queryAuthItemTwice("0");
			int k = 0;
			for (int i = 0; i < list.size(); i++) {
				list1 = authItemService.queryAuthCollect(schoolId, list.get(i).getPid());
				for (int j = 0; j < list1.size(); j++) {
					dataMap.put("level"+k, list1.get(j).getLevel());
					dataMap.put("value"+k, list1.get(j).getReview());
					if("".equals(list1.get(j).getMainProblem()) || StringUtils.isBlank(list1.get(j).getMainProblem())){
						dataMap.put("problem"+k, "二级指标达标,无需填写");
					}else{
						dataMap.put("problem"+k, list1.get(j).getMainProblem());
					}
					k++;
				}
			}
			
			String level = "A";
			String level1 = "B";
			String level2 = "C";
			
			AuthExpertItemData strA = authExpertItemMapService.queryNumber(schoolId, "1", level);
			AuthExpertItemData strB = authExpertItemMapService.queryNumber(schoolId, "1", level1);
			AuthExpertItemData strC = authExpertItemMapService.queryNumber(schoolId, "1", level2);
			dataMap.put("collect0", strA.getNumber());
			dataMap.put("collect1", strB.getNumber());
			dataMap.put("collect2", strC.getNumber());
			
			AuthItem ai = new AuthItem();
			ai = authItemService.queryIsfollow(schoolId, groupId);
			if(null != ai){
				String isfollow = ai.getIsfollow();
				if("0".equals(isfollow)){
					dataMap.put("isfollow", "进入现场考察");
				}else if("1".equals(isfollow)){
					dataMap.put("isfollow", "暂缓进入现场考察");
				}else if("2".equals(isfollow)){
					dataMap.put("isfollow", "重新申报");
				}
			}
			
			/* dataMap.put("title", "标题");   
			           
	        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();  
	         for (int i = 0; i < 10; i++) {  
	             Map<String,Object> map = new HashMap<String,Object>();  
	             map.put("xuehao", i);  
	            map.put("neirong", "内容"+i);  
	            list.add(map);
	         }
	         dataMap.put("list", list);*/
			
			DocumentHandler mdoc = new DocumentHandler();
			mdoc.createDoc7(request,response,dataMap, "D:/汇总表.doc");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 学校填报结果查询
	 */
	@RequestMapping(value = "/queryAuthMeterialSchool" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthMeterialSchool(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String, String> map){
		String expertId = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null== expertId){
			return toResponse(null, ReturnCode.FAIL, "未登录");
		}
		String pageSize = map.get("pageSize");
		String pageNumber = map.get("pageNumber");
		if(StringUtils.isBlank(pageNumber) || StringUtils.isBlank(pageSize)){
			return toResponse(null, ReturnCode.FAIL, "参数存在空值!");
		}
		try {
			Page<AuthSchool> page = authSchoolService.queryAuthSchoolPageByExportId(expertId, map);
			return toResponse(page, ReturnCode.SUCCESS, "查询成功!");
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.FAIL, "查询失败!");
		}
	}
	
	
	/**
	 * (管理员页面)材料汇总表--显示绑定学校的分项意见记录表列表中的学校
	 */
	@RequestMapping(value = "/queryAuthSchoolList1" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryAuthSchoolList1(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String, String> map){
		
		String pageSize = map.get("pageSize");
		String pageNumber = map.get("pageNumber");
		String groupId = map.get("pid");
		if(StringUtils.isBlank(pageNumber) || StringUtils.isBlank(pageSize) || StringUtils.isBlank(groupId)){
			return toResponse(null, ReturnCode.FAIL, "参数存在空值!");
		}
		try {
			Page<SchoolItemBean> page = authExpertSchoolMapService.queryAuthSchoolPageByGroupId1(groupId, map);
			return toResponse(page, ReturnCode.SUCCESS, "学校列表查询成功!");
			
		} catch (SQLException e) {
			e.printStackTrace();
			return toResponse(null, ReturnCode.SUCCESS, "学校列表查询失败!");
		}
		
	}

}
